<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>消息发送</title>
<link rel="shortcut icon" href="${path}/static/images/favicon.ico">
<link rel="stylesheet" type="text/css" href="${path}/static/plugins/layui/css/layui.css"/>
</head>

<body>
<fieldset class="layui-elem-field layui-field-title">
    <legend>消息发送</legend>
</fieldset>

<form class="layui-form" id="form" action="${path}/user/notice/addNotice" method="post">
    <input type="hidden" id="isTest" name="isTest" value="2" class="layui-input">
    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label">标题</label>
            <div class="layui-input-inline">
                <input type="text" name="title" lay-verify="title" autocomplete="off" class="layui-input" maxlength="20" value="温馨提示"/>
            </div>
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label">内容</label>
            <div class="layui-input-inline">
                <textarea type="text" name="content" lay-verify="content"
                          autocomplete="off" class="layui-input"
                          style="width: 650px;height: 450px;"></textarea>
            </div>
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label">发送人</label>
            <div class="layui-input-inline">
                <select name="isAll">
                    <option value="0">所有</option>
                    <option value="1">在线</option>
                    <option value="2">管理员</option>
                </select>
            </div>
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn" lay-submit="" lay-filter="sub" onclick="aa();">立即发送</button>
        </div>
    </div>
</form>

<!-- 全局js -->
<script src="${path}/static/Hui/js/jquery.min.js?v=2.1.4"></script>
<script src="${path}/static/Hui/js/bootstrap.min.js?v=3.3.6"></script>
<script src="${path}/static/plugins/layui/layui.js"></script>
<script type="text/javascript" src="${path}/static/plugins/validator.min.js" ></script>

<!-- 自定义js -->
<script src="${path}/static/Hui/js/content.js?v=1.0.0"></script>
<script>
    $(function(){
        // 模块加载
        layui.use(['form'], function() {
            var form = layui.form;

            //自定义验证规则
            form.verify({
                title: function(value) {
                    if (value.length < 2) {
                        return '标题至少得2个字符啊';
                    }
                },
                content: function(value){
                    if(value.length < 1){
                        return '内容不能为空';
                    }
                }
            });

            //监听指定开关
            // form.on('switch(switchBox)', function(data){
            //     this.checked ? $("#ishide").val(1):$("#ishide").val(2);
            // });

            //监听提交
            form.on('submit(sub)', function(){
                var action = $("#form").attr("action");
                layer.confirm('确认发送公告?', {
                    btn: ['确定','取消']
                }, function() {
                    $.ajax({
                        type: "post",
                        url: action,
                        data: $('#form').serialize(),
                        dataType:"json",
                        success: function (data) {
                            if (data.code == 0) {
                                layer.alert(data.msg, {icon: 1});
                            } else {
                                layer.alert(data.msg, {icon: 2});
                            }
                        }
                    });
                });
                return false;
            });
        });
    });
</script>
</body>
</html>